/*
 * Created on Jul 23, 2004
 */
package cheme.ProcessEditor.Actions;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.IEditorPart;

/**
 * Action to toggle the layout between manual and automatic
 * 
 * @author Phil Zoio
 */
public class FlyoutChangeLayoutAction extends Action
{

	IEditorPart editor;

	boolean checked;

	public FlyoutChangeLayoutAction(IEditorPart editor)
	{
		super("Automatic Layout", Action.AS_CHECK_BOX);
		this.editor = editor;
	}

	public void run()
	{
		setChecked(true);
	}

	public boolean isChecked()
	{
		if(editor != null)
		{
			return isChecked(editor);
		}
		else
		{
			return super.isChecked();
		}
	}

	/**
	 * @see org.eclipse.jface.action.IAction#isChecked()
	 */
	public boolean isChecked(IEditorPart editor)
	{
		return true;
	}

	public void setActiveEditor(IEditorPart editor)
	{
		this.editor = editor;
		boolean localChecked = isChecked(editor);

		//there appears to be a bug in the framework which necessitates this
		if(localChecked)
		{
			firePropertyChange(CHECKED, Boolean.FALSE, Boolean.TRUE);
		}
		else
		{
			firePropertyChange(CHECKED, Boolean.TRUE, Boolean.FALSE);
		}
	}

}